package com.learn.app.user.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class BaseController {
	private static final Logger log = LoggerFactory.getLogger(BaseController.class);

	/**
	 * 返回json格式数据
	 * 
	 * @author liangan
	 * @param data
	 * @param res
	 */
//	protected void writeJson(String data, HttpServletResponse res) {
//		writeJson(data, res, "utf-8");
//	}
//
//	protected void writeJson(String data, HttpServletResponse res,
//			String charset) {
//		res.setContentType("text/html; charset=" + charset.toLowerCase());
//		PrintWriter pw = null;
//		try {
//			pw = res.getWriter();
//			pw.print(data);
//			pw.flush();
//			pw.close();
//		} catch (IOException e) {
//			log.error(e.getMessage());
//		} finally {
//			if (null != pw) {
//				pw.close();
//			}
//		}
//	}

	/**
	 * 获取json数据，返回对象
	 * 
	 * @author liangan
	 * @param jsonString
	 * @param cls
	 * @return
	 */
//	protected <T> T objectFromJson(String jsonString, Class<T> cls) {
//		return JSON.parseObject(jsonString, cls);
//	}
//
//	//dm为返回的数据对象
//	protected void writeString(HttpServletResponse response, String str) {
//		writeJson(JSON.toJSONString(str), response, "utf-8");
//	}

}
